<?php
include_once 'inc/config.inc.php';
include_once 'inc/mysql.inc.php';
include_once 'inc/tool.inc.php';

$template["title"] = "用户登录";
$link = connect();

if(is_login($link)){
    skip("index.php", "error", "你已经登录，请不要重复登录！");
}

if(isset($_POST['submit'])){
    include_once 'inc/check_login.inc.php';
    escape($link, $_POST);
    $query = "select * from kuse_member where name = '{$_POST['name']}' and pw = md5('{$_POST['pw']}')";
    $result = execute($link, $query);
    if(mysqli_num_rows($result) == 1){
        setcookie('kuse[name]', $_POST['name'], time()+$_POST['time']);
        setcookie('kuse[pw]', md5($_POST['pw']), time()+$_POST['time']);
        skip("index.php", 'ok', '登录成功！');
    }else{
        skip("login.php", 'error', "账号或密码错误！");
    }
}

?>
<?php include_once 'inc/header.inc.php';?>

    <!-- 主体代码开始 -->
    <div class="register content-box">
        <h2>请登录</h2>
        <form method="post" class="clearfix">
            <label>账号：<input type="text" name="name"></label>
            <label>密码：<input type="password" name="pw"></label>
            <label>自动登录：
                <select name="time" style="width: 236px; height:25px;">
                    <option value="3600">1小时内</option>
                    <option value="86400">1天内</option>
                    <option value="259200">3天内</option>
                    <option value="2592000">30天内</option>
                </select>
            </label>
            <div style="clear:both"></div>
            <input name="submit" class="btn" type="submit" value="登录">
        </form>
    </div>
    <!-- 主体代码结束 -->

<?php include_once 'inc/footer.inc.php'; ?>